<template>
  <div>
    <div class="wordMenu">
      <input type="text" v-model="searchText" />
      <button @click="onSearch">搜索</button>
      <button @click="onCreate">创建</button>
      <button @click="onSave">保存</button>
    </div>
    <div class="wordList">
      <div class="wl-item" v-for="(word, index) in nature.list" :key="index">
        <div class="wl-word">
          Word:
          <input type="text" v-model="word.word" />
        </div>
        <div class="wl-word-mean wlWordMean wwm">
          <div class="wwm-list">
            <div class="wwm-item" v-for="(mean, mi) in word.means" :key="mi">
              <div class="wwm-hd">
                <div>Mean:</div>
                <div class="wwm-type"></div>
                <div class="wwm-text">
                  <input type="text" v-model="mean.text" />
                </div>
              </div>
              <div class="wwd-instances wwdInstance win">
                <div class="win-list">
                  <div class="win-item" v-for="(instance, ii) in mean.instances" :key="ii">
                    <div class="win-en">
                      en:
                      <input type="text" v-model="instance.en" />
                    </div>
                    <div class="win-zh">
                      zh:
                      <input type="text" v-model="instance.zh" />
                    </div>
                  </div>
                </div>
                <div class="win-create" @click="addWordMeanInstances(mean)">创建Instance</div>
              </div>
            </div>
          </div>
          <div class="wwm-create" @click="addWordMeans(word)">创建Mean</div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      searchText: '',
      nature: {
        list: []
      }
    }
  },
  methods: {
    saveToJSON() {},
    loadFromJSON() {},
    searchWord() {},
    onCreate() {
      this.nature.list.push({
        word: '', //单词
        note: '', //笔记
        means: []
      })
    },
    addWordMeans(word) {
      debugger
      word.means.push({
        wordType: '', //单词类型
        text: '', //解释
        note: '', //笔记
        instances: []
      })
    },
    addWordMeanInstances(mean) {
      mean.instances.push({
        en: '', //英文
        zh: '', //中文
        note: '' //笔记
      })
    }
  }
}
</script>
